/**
 *
 * @export
 * @description 获取storage
 * @param {*} key
 * @return {*}
 */
export function getStorage(key) {
	if (!key) return
	let source = window.localStorage.getItem(key)
	if (!source) return
	source = JSON.parse(source)
	if (Date.now() - source.time > source.expire) {
		localStorage.removeItem(key)
		return null
	}
	return source.data
}

/**
 * @export
 * @description 设置storage
 * @param {*} key
 * @param {*} data
 * @param {*} expire 过期时间
 */
export function setStorage(key, data, expire = 7 * 24 * 60 * 60 * 1000) {
	if (!key) return
	let source = {
		data,
		time: Date.now(),
		expire,
	}
	source = JSON.stringify(source)
	window.localStorage.setItem(key, source)
}
/**
 * @export
 * @description 清除storage
 * @param {String} key
 */
export function removeStorage(key) {
	if (!key) return
	window.localStorage.removeItem(key)
}
